require(['loading'], function(loading) {
	
	//应用实例化
	var address = new Vue({
		el: '#address',
		data: {
			addressList: [],
			showLoading: false,
			addrListUrl: wxUrl + '/v3.2/addr/addrList',
			defaultUrl: wxUrl + '/v3.2/addr/setDefaultAddr',
			saveAddrUrl: wxUrl + '/v3.2/addr/saveAddr',
			deleteUrl: wxUrl + '/v3.2/addr/delAddr',
			item: {
				params:{
					token: token,
					userToken: userToken
				}
			},
			item2: {
				params:{
					token: token,
					userToken: userToken,
					addrId: ''
				}
			}
		},
		ready: function() {
	        this.getAddrList();
	    },
		methods: {
			getAddrList: function() {
				//获取地址列表
				this.$http.get(this.addrListUrl, this.item)
					.then(function(response) {
						var result = JSON.parse(response.body);
						this.$set('addressList', result.data.addrList);
					},function(response) {
						//errorCallback
					});
			},
			setDefaultAddr: function(e) {
				//设为默认地址
				this.item2.params.addrId = $(e.currentTarget).attr('id');
				this.$http.get(this.defaultUrl, this.item2)
					.then(function(response) {
						var result = JSON.parse(response.body);
						for(var i=0; i<this.addressList.length; i++){
							if(this.addressList[i].isDefault){
								this.addressList[i].isDefault = 0;
							}
							if(this.addressList[i].id == this.item2.params.addrId){
								this.addressList[i].isDefault = 1;
							}
						}
					},function(response) {
						//errorCallback
					});
			},
			deleteAddr: function(e){
				//删除地址
				this.item2.params.addrId = $(e.currentTarget).siblings('.fq_moren').attr('id');
				this.$http.get(this.deleteUrl, this.item2)
					.then(function(response) {
						var result = JSON.parse(response.body);
						this.getAddrList();
						/*location.reload();
						for(var i=0; i<this.addressList.length; i++){
							if(this.addressList[i].id == this.item2.params.addrId){
								this.addressList.splice(i,1);
							}
						}*/
					},function(response) {
						//errorCallback
					});
			},
			selectAddr: function(e){
				var goodsId = localStorage.getItem('submitOrder-goodsId');
				if(goodsId !=null && goodsId != ''){
					var thisId = $(e.currentTarget).attr('id');
					localStorage.setItem('addrId',thisId);
					window.location.href="../../bigSupply/submitOrder.html?id=" + goodsId;
				}
			}
		}
	});
});
// 为可控制返回指定页面所有添加pushState
history.pushState({}, document.title, null);
pushVHistory();
window.addEventListener("popstate", function() {
    // 跳转到订单列表页面
	goBackVHistory();
});
